package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.impl.SetmealServiceImpl;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Log4j2
@RestController
@RequestMapping("/setmeal")
public class SetmealController {
   @Autowired
    private SetmealServiceImpl setmealServiceImpl;

    /**
     * 添加套餐
     */
    @PostMapping
    public Result add(@RequestBody Setmeal setmeal){
        return setmealServiceImpl.add(setmeal);
    }


    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    public Result getbyid(@PathVariable String id){
        return setmealServiceImpl.getbyid(id);
    }

    /**
     * 分页查询套餐
     */
    @GetMapping("/page")
    public Result page(String name,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize){
        return setmealServiceImpl.page(name,page,pageSize);
    }


    /**
     * 删除套餐
     */
    @DeleteMapping
    public Result delete(String ids){
        return setmealServiceImpl.delect(ids);
    }

    /**
     * 套餐上下架
     */
    @PostMapping("/status/{status}")
    public Result auto(@PathVariable int status,String ids){
        return setmealServiceImpl.auto(status,ids);
        }
    /**
     * 修改套餐
     */
    @PutMapping
    public Result update(@RequestBody Setmeal setmeal){
        return setmealServiceImpl.update(setmeal);
    }


}
